package com.byzk.p2p.admin.money.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.DateUtils;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.money.service.FundRecordService;
import com.byzk.p2p.admin.money.vo.FundRecordUserVo;

/**
 * 资金流水Controller
 * 
 * @author suker.zhou
 *
 */
@Controller
@RequestMapping("/admin/fundRecord")
public class FundRecordController extends AdminBaseController {

	@Autowired
	private FundRecordService fundRecordService;

	/**
	 * 资金流水记录
	 * @param model 视图对象
	 * @param index 当前页
	 * @param limit 每页显示条数
	 * @param username 用户名
	 * @param type 资金流水类型
	 * @return
	 */
	@RequestMapping("/list")
	public String listFundRecord(Model model,
					@ModelAttribute FundRecordUserVo fundRecordUserVo,
					@RequestParam(value="index",required=false,defaultValue="1") int index,
					@RequestParam(value="limit",required=false,defaultValue="10") int limit,
					@RequestParam(value="createTimeBegin",required=false) String createTimeBegin,
					@RequestParam(value="createTimeEnd",required=false)String createTimeEnd)throws Exception {
		fundRecordUserVo.setIndex(index);
		fundRecordUserVo.setLimit(limit);
		if (StringUtils.isNotBlank(fundRecordUserVo.getUsername())) {
			fundRecordUserVo.setMatchUser(fundRecordUserVo.getUsername());
			model.addAttribute("username", fundRecordUserVo.getUsername());
		}
		if (fundRecordUserVo.getType() != null) {
			model.addAttribute("type", fundRecordUserVo.getType());
		}
		if (StringUtils.isNotBlank(createTimeBegin)) {
			fundRecordUserVo.setPublishTimeStart(DateUtils.getRealDate(DateUtils.convert(createTimeBegin, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			model.addAttribute("createTimeBegin", createTimeBegin);
		}
		if (StringUtils.isNotBlank(createTimeEnd)) {
			fundRecordUserVo.setPublishTimeEnd(DateUtils.getFullDate(DateUtils.convert(createTimeEnd, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
			model.addAttribute("createTimeEnd", createTimeEnd);
		}
		PageInfo<FundRecordUserVo> pageInfo = fundRecordService.list(fundRecordUserVo);
		model.addAttribute("pageInfo", pageInfo);
		return ftl(Thread.currentThread().getStackTrace());
	}
	
}
